package com.cos.config.thread.pool;

import java.util.concurrent.ThreadFactory;

/**
 * @author Irving
 * @create 2021/7/19
 * @desc 线程工厂,每次线程池创建线程都会调用
 **/
public class COSThreadFactory implements ThreadFactory {
    /**
     * 线程池中线程的数量
     */
    private int threadCount;

    @Override
    public Thread newThread(Runnable runnable) {
        threadCount++;
        Thread thread = new Thread(runnable);
        thread.setName("COS-THREAD-" + threadCount);
        thread.setDaemon(false);
        System.err.println("当前线程:" + thread.getName() + ",线程池数量:" + threadCount);
        return thread;
    }
}
